package com.zzit.vjv.controller.documentReview_controller.backend;

import com.zzit.vjv.biz.documentReview_biz.backend.BackendLoginBiz;
import com.zzit.vjv.entity.documentReview_entity.BackendUser;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


/**
 * 后台登录控制器
 */
@Controller("loginController")
public class LoginController {


    @Resource(name = "backendLoginBiz")
    private BackendLoginBiz backendLoginBiz;

    /**
     * 登录方法
     * @return
     */
    @RequestMapping(value = "/login" ,method = RequestMethod.POST,params = {"userCode","userPassword"})
    public String loginBackend(BackendUser backendUser, HttpSession httpSession, Model model){

        //接收查询出来的后台用户对象
        BackendUser backendUser1=backendLoginBiz.byFindUserCodeAndUserPassword_login(backendUser);

        System.out.println(backendUser1+"/"+backendUser.getUserCode());

        if(backendUser1!=null){

            httpSession.setAttribute("userSession",backendUser1);

            System.out.println("进来");


            return "jsp/backend/main";

        }else{


            model.addAttribute("bug","用户名或密码错误");


            System.out.println("出问题");
            return "forward:jsp/backendlogin.jsp";

        }






    }




}
